﻿using System.Data.Entity;
using Edikgale.Samples.Domain;

namespace Edikgale.Samples.Data
{
    public class EdikgaleEfContext: DbContext 
    {
        public DbSet<Author> Authors { get; set; }
        public DbSet<Book> Books { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Book>()
                .HasMany(b => b.Authors)
                .WithMany(a => a.Books)
                .Map(m =>
                    {
                        m.MapLeftKey("BookId");
                        m.MapRightKey("AuthorId");
                        m.ToTable("BookAuthor");
                    });

            base.OnModelCreating(modelBuilder);
        }
    }
}
